﻿using spriteeditor.WorkingSpace;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace spriteeditor
{
    //此处集中所有的NodeTag，NodeTag 作为TreeView Item的一个标记，同时用于在PropertyGrid中显示
    public interface INodeTag
    {
        public string Type
        {
            get;
        }
    }
    public class NodeTag_NewTexList : INodeTag
    {
        public string Type => "TexList";
    }
    public class NodeTag_SpriteList : INodeTag
    {
        public string Type => "SpriteList";
    }
    public class NodeTag_Sprite : INodeTag
    {
        public string Type => "Sprite";

        string _tname = null;
        public string Name
        {
            get
            {
                return _tname == null ? sprite.name : _tname;
            }
            set
            {
                _tname = value;
            }
        }
        public string FileName
        {
            get
            {
                return sprite.filename;
            }
        }



        string _tplayername;
        public string PlayerName
        {
            get
            {
                return _tplayername == null ? sprite.playername : _tplayername;
            }
            set
            {
                _tplayername = value;
            }
        }
        string _tpartname;
        public string PartName
        {
            get
            {
                return _tpartname == null ? sprite.part_name : _tpartname;
            }
            set
            {
                _tpartname = value;
            }
        }
        string _tpartskin;
        public string PartSkin
        {
            get
            {
                return _tpartskin == null ? sprite.part_skin : _tpartskin;
            }
            set
            {
                _tpartskin = value;
            }
        }
        string _tpartid;
        public string PartID
        {
            get
            {
                return _tpartid == null ? sprite.part_id : _tpartid;
            }
            set
            {
                _tpartid = value;
            }
        }
        string _tresgroup;
        public string ResGroup
        {
            get
            {
                return _tresgroup==null?sprite.resgroup:_tresgroup;
            }
            set
            {
                _tresgroup = value;
            }
        }
        public Rectangle UV
        {
            get
            {
                return sprite.uv;
            }

        }
        Point? _tpovit;
        public Point Povit
        {
            get
            {
                return _tpovit == null ? sprite.povit : _tpovit.Value;
            }
            set
            {
                _tpovit = value;
            }
        }
        public SkinSprite sprite;

        public void Revert()
        {
            this._tresgroup = null;
            this._tpovit = null;
            this._tname = null;
            this._tplayername = null;
            this._tpartname = null;
            this._tpartskin = null;
            this._tpartid = null;
        }
        public void Save()
        {
            if(this._tresgroup!=null)
            {
                sprite.resgroup = this._tresgroup;
            }
            if (this._tpovit != null)
            {
                sprite.povit = this._tpovit.Value;
            }
            if (this._tname != null)
            {
                sprite.name = this._tname;
            }
            if (this._tplayername != null)
            {
                sprite.playername = this._tplayername;
            }
            if (this._tpartname != null)
            {
                sprite.part_name = this._tpartname;
            }
            if (this._tpartskin != null)
            {
                sprite.part_skin = this._tpartskin;
            }
            if (this._tpartid != null)
            {
                sprite.part_id = this._tpartid;
            }
            Revert();
        }
    }

    public class NodeTag_NewTex : INodeTag
    {
        public string Type => "独立的贴图，先转换成精灵才能使用";
        public string TexName
        {
            get
            {
                return texname;
            }
        }
        public string Filename
        {
            get
            {
                return filename;
            }
        }
        public string texname;

        public string filename;

    }
}
